package com.pokermind.operator;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Primary;

import java.util.List;

/**
 * 真实AI测试配置类
 * 用于Spring Boot测试上下文
 * 
 * @author PokerMind Team
 */
@SpringBootApplication
@ComponentScan(basePackages = {
    "com.pokermind.common",
    "com.pokermind.model", 
    "com.pokermind.operator"
})
public class RealAITestConfiguration {

    public static void main(String[] args) {
        SpringApplication.run(RealAITestConfiguration.class, args);
    }

    /**
     * 默认ChatClient配置 - 使用第一个可用的ChatModel
     */
    @Bean
    @Primary
    @ConditionalOnClass(ChatModel.class)
    @ConditionalOnBean(ChatModel.class)
    public ChatClient defaultChatClient(List<ChatModel> chatModels) {
        if (chatModels.isEmpty()) {
            return null; // 没有可用的ChatModel
        }
        return ChatClient.builder(chatModels.get(0)).build();
    }

    /**
     * OpenAI ChatClient配置
     */
    @Bean("openaiChatClient")
    @ConditionalOnClass(ChatModel.class) 
    @ConditionalOnProperty(name = "pokermind.ai.providers.openai.enabled", havingValue = "true")
    @ConditionalOnBean(ChatModel.class)
    public ChatClient openaiChatClient(List<ChatModel> chatModels) {
        // 这里应该选择OpenAI的ChatModel，为简单起见使用第一个
        if (chatModels.isEmpty()) {
            return null;
        }
        return ChatClient.builder(chatModels.get(0)).build();
    }
}
